<?php
/**
 * Created by PhpStorm.
 * User: 共赢岛
 * Date: 2023/12/19
 * Time: 17:05
 */

namespace App\Services\LifeCycle;


use App\Models\CarPackageOrderAgreement;
use Illuminate\Support\Facades\Auth;

class OrderAgreementService
{
    public static function one($condition = [])
    {
        $user = Auth::user();
        $condition['user_id'] = $user->id;

        return CarPackageOrderAgreement::where($condition)->first();
    }

    public static function save($param = [])
    {
        $order = OrderService::detail($param['order_id']);
        $agreement = $order->package->agreement;

        if ($order->store->package_agreement) {
            $agreement = $order->store->package_agreement.'<br />'.$order->package->agreement;
        }

        $order->agreement_url = $param['pic_url'];
        $order->agreement_at = date('Y-m-d H:i:s', time());
        $order->save();

        CarPackageOrderAgreement::create([
            'order_id' => $order->id,
            'user_id' => $order->user_id,
            'pic_url' => $param['pic_url'],
            'content' => $agreement
        ])->id;

        return true;
    }
}